<template>
  <div class="head">
    <div class="tit">
      <p>主题宴助理e平台 - {{ title }}</p>
    </div>
    <div class="back">
      <img
        v-if="left"
        class="back_left"
        :src="img.leftpicth"
        @click="historyprocess(-1)"
      />
      <img v-else class="back_left forbid" :src="imgs.left" />
      <img
        v-if="right"
        class="back_right"
        :src="img.rightpicth"
        @click="historyprocess(1)"
      />
      <img v-else class="back_right forbid" :src="imgs.right" />
    </div>
    <div class="save" v-show="ifsave" @click="savepicClick">
      <img :src="imgs.save" alt="" />
      <span>保存</span>
    </div>
    <div class="save" v-show="!ifsave" @click="savepicClick1(1)">
      <img :src="img.localdownload" alt="" />
      <span>保存本地</span>
    </div>
    <div
      class="save"
      v-show="!ifsave"
      @click="savepicClick2"
      :style="{ cursor: savetoClipBoardBtn ? 'pointer' : 'not-allowed' }"
    >
      <!-- cursor: pointer; -->
      <img :src="img.copy" alt="" />
      <span>保存剪切板</span>
    </div>
    <div class="headimgs">
      <div class="headimg" @click="headimgClick">
        <img :src="img.caidan" alt="" />
        <p>菜单</p>
      </div>
      <div class="headimg_name">{{ name }}</div>
      <div class="headimg_online">
        当前在线： <strong style="color:#000">{{ online }}</strong>
        人
      </div>
    </div>
    <transition-group name="list-headimg" :duration="1000">
      <div
        class="headimg_list"
        v-if="headSwitch"
        @mouseleave.stop="headimgMouseleave"
        :key="1"
      >
        <div
          class="headimg_div"
          v-for="(v, i) in headList"
          :key="i"
          @click="headListClick(i)"
        >
          <router-link :to="v.link"> {{ v.text }} </router-link>
        </div>
      </div>
    </transition-group>
  </div>
</template>
<script>
import { mapState } from "vuex";
import mixin from "@/utils/mixin";

export default {
  mixins: [mixin],
  computed: {
    ...mapState("templateStage", [
      "listNote",
      "listImg",
      "listEllipse",
      "historycurrentpage",
      "historylist",
      "savetoClipBoardBtn",
    ]),

    //向左是回退 长度大于0可回退
    left: function () {
      if (this.historycurrentpage > 1) return true;
      else return false;
    },
    //向右前进 if 进程-长度大于0可前进
    right: function () {
      if (this.historylist.length - this.historycurrentpage > 0) {
        return true;
      } else return false;
    },
  },
  props: ['title','process','online'],
  watch: {
    process(nval,oval) {
      let value=nval-oval
      if (value == -1 && this.left == true) this.historyprocess(value);
      else if (value == 1 && this.right == true) this.historyprocess(value);
    },
  },
  data() {
    return {
      imgs: {
        left: require("@/assets/img/left.png"),
        right: require("@/assets/img/right.png"),
        save: require("@/assets/img/save.png"),
        head: "https://img1.baidu.com/it/u=2821135284,1986086101&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
      },
      //头像——列表
      headList: [
        {
          text: "内容图编辑",
          link: "/content",
        },
        {
          text: "欢迎屏编辑",
          link: "",
          // link: "/welcome",
        },
        {
          text: "新建模板",
          link: "/template",
        },
        {
          text: "用户管理",
          link: "",
        },
        {
          text: "切换账号",
          link: "/login",
        },
      ],
      permission: false,
      //头像——列表是否出现
      headSwitch: false,
      ifsave: null,
      name: window.localStorage.getItem("eplatformname"),
    };
  },
  methods: {
    headListClick() {
      //
    },
    //头像——点击——列表显示隐藏
    headimgClick() {
      this.headSwitch = !this.headSwitch;
    },
    headimgMouseleave() {
      this.headSwitch = false;
    },
    savepicClick() {
      this.$emit("save", null);
      this.$store.commit("templateStage/CLEARREATLIST", []);
    },
    savepicClick1(type) {
      this.$emit("save", type);
      this.$store.commit("templateStage/CLEARREATLIST", []);
    },
    savepicClick2() {
      if (!this.savetoClipBoardBtn) {
        return;
      }
      this.$emit("save", null);
      this.$store.commit("templateStage/CLEARREATLIST", []);
    },
    //历史进程
    historyprocess(value) {
      this.$emit("historyprocess", value);
      this.$emit("layerstool");
    },
  },
  mounted() {
    if (this.title == "新建模板") this.ifsave = true;
    else this.ifsave = false;
    if (window.localStorage.getItem("eplatformpowertype") == 0)
      this.headList.splice(3, 1);
     
  },
};
</script>

<style lang="less" scoped>
@import "../../assets/styles/frame.less";
.black {
  color: #2b2b2b;
}
.forbid {
  pointer-events: none;
}
.list-headimg-enter,
.list-headimg-leave-to {
  opacity: 0;
  transform: translateY(10px);
  transform: translateX(-20px);
}
// .list-headimg-leave-active {
//   position: absolute;
// }
.head {
  width: 100vw;
  height: 58px;
  box-sizing: border-box;
  padding: 0 34px;
  position: relative;
  .divDA();
  & img {
    width: 24px;
    height: 24px;
  }
  .tit {
    font-size: 20px;
    color: @color2;
  }
  .back {
    margin-left: 120px;
    .back_left {
      margin-right: 20px;
    }
    .back_right {
      margin-right: 34px;
    }
  }
  .save {
    height: 24px;
    margin-left: 20px;
    .divDJ();
    img {
      width: 24px;
      height: 24px;
    }
    span {
      margin-left: 8px;
      line-height: 24px;
    }
  }
  .headimgs {
    position: absolute;
    right: 80px;
    top: 17px;
    width: 255px;
    height: auto;
    // background: #2b2b2b;
    .divAJS();
    .headimg {
      width: 73px;
      height: 26px;
      // margin-right: 20px;
      // .divAJS();
      padding: 5px 13px;
      background: #dad9d9;
      border-radius: 13px;
      overflow: hidden;
      vertical-align: top;
      cursor: pointer;
      font-weight: 600;
      color: #2b2b2b;
      img {
        width: 14px;
        height: 14px;
        //   position: relative;
        // left: 5px;
        // top: -2px;
      }
      p {
        display: inline-block;
        font-size: 14px;
        position: relative;
        left: 5px;
        top: -2px;
      }
    }
    .headimg_name {
      font-size: 14px;
      font-weight: 600;
      color: #2b2b2b;
      position: relative;
      top: -2px;
    }
    .headimg_online {
      // margin-left: 20px;
    }
  }

  .headimg_list {
    position: absolute;
    z-index: 9999999;
    top: 48px;
    right: 173px;
    width: 170px;
    // height: 195.5px;
    background-color: #fff;
    border-radius: @radius1;
    padding: 16px 34px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 1px 4px 5px #7878786c;
    transition-property: transform; /* 设置宽度有过渡效果 */
    transition-duration: 0.8s; /* 设置过渡时间为 3s */
    // transition-delay: 1s;   /* 设置延迟时间为 1s */
    font-weight: 600;
    font-family: Lantinghei SC;
    .headimg_div {
      width: 100%;
      height: 25.5px;
      border-radius: @radius1;
      margin-bottom: 10px;
      border: 1px solid #cacaca;
      text-align: center;
      line-height: 25.5px;
      color: @color2;
      &:last-child {
        margin-bottom: 0px;
      }
    }
  }
}
</style>